package com.wc.AlgoOJ_train.train1.c4.A408;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/9 14:54
 * @description a/b + c/d
 * http://43.138.190.70:8888/p/A408
 */
public class Main {
    static FastReader in = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        while (n-- > 0) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();
            int e = a * d + b * c;
            int f = b * d;
            int gc = gcd(e, f);
            out.print(e / gc);
            out.print(" ");
            out.println(f / gc);
        }
        out.flush();
    }

    static int gcd(int a, int b) {
        if (a > b) {
            return gcd(b, a);
        }
        while (b % a > 0) {
            int tmp = b % a;
            b = a;
            a = tmp;
        }
        return a;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}
